import type { ApiResponse, ApprovalProcess, ApprovalProcessParams } from './types'
import request from '/@/utils/request'

// 获取所有父级审批流程
export const getParentApprovalProcess = () => {
  return request<ApiResponse<ApprovalProcess[]>>({
    url: '/api/approvalProcess/parent',
    method: 'get',
  })
}

// 根据父级获取树状列表
export const getApprovalProcessTree = () => {
  return request<ApiResponse<ApprovalProcess[]>>({
    url: '/api/approvalProcess',
    method: 'get',
  })
}

// 新增审批流程
export const addApprovalProcess = (data: ApprovalProcessParams) => {
  return request<ApiResponse<null>>({
    url: '/api/approvalProcess',
    method: 'post',
    data,
  })
}

// 获取审批流程详情
export const getApprovalProcessDetail = (id: string | number) => {
  return request<ApiResponse<ApprovalProcess>>({
    url: `/api/approvalProcess/show/${id}`,
    method: 'get',
  })
}

// 修改审批流程
export const updateApprovalProcess = (id: string | number, data: ApprovalProcessParams) => {
  return request<ApiResponse<null>>({
    url: `/api/approvalProcess/${id}`,
    method: 'put',
    data,
  })
}

// 删除审批流程
export const deleteApprovalProcess = (id: string | number) => {
  return request<ApiResponse<null>>({
    url: `/api/approvalProcess/${id}`,
    method: 'delete',
  })
}
